import { create, update, remove, query } from '../../../../../framework/service/index';
import { Toast } from 'antd-mobile';

const delay = timeout => {
  return new Promise(resolve => {
    setTimeout(resolve, timeout);
  });
};
const proIcon = require('../../../../../icons/personal/default-avatar.jpg')
export default {

  namespace: 'addAppraise',

  state: {
    date: [],
    selfEvaluate: '',
    id: 0,
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if(location.pathname === '/add-appraise') {
          dispatch({
            type: 'query',
          })
        }
      })
    },
  },



  effects: {
    *query({ payload }, { call, put }) {


      const { code, data, message } = yield call(query, '/api/applicant/resume', {});

      if ( code == 200 && data ) {
        console.log('获取简历');
        console.log(data.id);
        yield put({
          type: 'querySuccess',
          payload: {
            id: data.id,
            selfEvaluate: data.selfEvaluate
          }
        })
      }

      const proIcon = proIcon
    },
    *putApprasie({ payload }, { call, put, select }) {
      const id = yield select (({addAppraise}) => addAppraise.id);
      let selfEvaluate = ""
      let resume = {}
      if (payload.data.selfEvaluate==undefined) {
        selfEvaluate = ""
      } else {
        selfEvaluate = payload.data.selfEvaluate;
      }
      resume = {id: id ,selfEvaluate: selfEvaluate };

      console.log('resume123',JSON.stringify(resume));

      const { code, data, message } = yield call(update, '/api/applicant/resume', {...resume});
      if (code==200 &&　data ) {

        Toast.success("保存成功",1);
        yield call(delay, 1000);
        history.go(-1);
      }
    }
  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
